package com.crm.system.controller.sys;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.sys.permissionManagement.SysIssueInvoice;
import com.crm.model.vo.sys.IssueInvoiceVO;
import com.crm.system.service.sys.IssueInvoiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author:chaifuyou
 * @Date: 2021/7/22 13:54
 */
@RestController
@RequestMapping("/issueInvoice")
@Slf4j
public class IssueInvoiceController {

    @Autowired
    private IssueInvoiceService issueInvoiceService;

    /**
     * 分页查询分公司开票列表
     * @param pageIndex
     * @param pageSize
     * @param companyName
     * @return
     */
    @PostMapping("/selectIssueInvoiceList")
    public DataResponse selectIssueInvoiceList(@RequestParam(value = "pageIndex", required = false) Integer pageIndex,//页码
                                               @RequestParam(value = "pageSize", required = false) Integer pageSize,//分页大小
                                               @RequestParam(value = "companyName", required = false) String companyName ){
        DhPageInfo<IssueInvoiceVO> pageVOList = issueInvoiceService.selectIssueInvoiceList(pageIndex,pageSize,companyName);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),pageVOList);
    }

    /**
     * 根据分公司查询开票公司列表
     * @param pageIndex
     * @param pageSize
     * @param companyId
     * @return
     */
    @PostMapping("/selectInvoiceCompanyList")
    public DataResponse selectInvoiceCompanyList(@RequestParam(value = "pageIndex", required = false) Integer pageIndex,//页码
                                                 @RequestParam(value = "pageSize", required = false) Integer pageSize,//分页大小
                                                 @RequestParam(value = "companyId", required = true) String companyId ){
        DhPageInfo<IssueInvoiceVO> pageVOList = issueInvoiceService.selectInvoiceCompanyList(pageIndex,pageSize,companyId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),pageVOList);
    }

    /**
     * 增加分公司开票公司
     * @return
     */
    @PostMapping("/addCompanyIssueInvoice")
    public DataResponse addCompanyIssueInvoice(@RequestBody SysIssueInvoice sysIssueInvoice){
        issueInvoiceService.addCompanyIssueInvoice(sysIssueInvoice);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /**
     * 删除分公司开票信息
     * @return
     */
    @PostMapping("/delCompanyIssueInvoice")
    public DataResponse delCompanyIssueInvoice(String companyId){
        issueInvoiceService.delCompanyIssueInvoice(companyId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /**
     * 删除开票信息
     * @return
     */
    @PostMapping("/delIssueInvoice")
    public DataResponse delIssueInvoice(String issueInvoiceId){
        issueInvoiceService.delIssueInvoice(issueInvoiceId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }
}
